/**
 * 
 */
package org.manggis.io;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author ppacka
 *
 */
public abstract class Resource extends InputStream {

	protected String resourcePath;
	private String prefix;
	private InputStream resourceStream;
	
	public final static String CLASS_PREFIX = "class://";
	public final static String FILE_PREFIX = "file://";
	
	public Resource(String resourcePath, String prefix) {
		this.resourcePath = resourcePath;
		this.prefix = prefix;
	}
	
	public int read() throws IOException {
		if (resourceStream == null) {
			resourceStream = getResourceStream();
		}
		return resourceStream.read();
	}
	
	protected abstract InputStream getResourceStream() throws IOException;

	public String getResourceURI() {
		return prefix + resourcePath;
	}
	
}

